<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
   <form action="" method="post" class="layui-form layui-form-pane" id="DataForm">
    <div class="layui-form-item">
        <label class="layui-form-label">选择分类</label>
        <div class="layui-input-block">
            <select name="pid">
                <option value="">请选择</option>
                <option value="0" {:$info.pid==0?'selected':''}>顶级分类</option>
                {foreach $menu as $key=>$val}
                    <option value="{$val.id}" {:$info.pid==$val.id?'selected':''}>{$val.title}</option>
                    {notempty name="val.child"}
                        {foreach $val.child as $k=>$v}
                        <option value="{$v.id}" {:$info.pid==$v.id?'selected':''}>　|-　{$v.title}</option>
                        {/foreach}
                    {/notempty}
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入菜单名称" value="{$info.title}" class="layui-input">
        </div>
    </div>

      
    <div class="layui-form-item">
        <label class="layui-form-label">封面</label>
        <div class="layui-input-block">
            <input type="text" name="img" id="img" autocomplete="off"
                class="layui-input layui-col-xs6" readonly placeholder="请选择图片上传" value="{$info.img}">
            <div class="layuimini-upload-btn">
                <button type="button" class="layui-btn" id="upload_img"><i
                        class="fa fa-upload"></i>
                    上传图片</button>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="text" name="sort" placeholder="请输入排序" value="{$info.sort}" class="layui-input">
        </div>
    </div>
  

    <div class="layui-form-item">
        <label class="layui-form-label">文字推荐</label>
        <div class="layui-input-block">
            <input type="radio" name="is_txt_index" value="0" title="否" {:$info.is_txt_index==0?'checked':''}>
            <input type="radio" name="is_txt_index" value="1" title="是" {:$info.is_txt_index==1?'checked':''}>
        </div>
    </div>

    
    <div class="layui-form-item">
        <label class="layui-form-label">图标推荐</label>
        <div class="layui-input-block">
            <input type="radio" name="is_img_index" value="0" title="否" {:$info.is_img_index==0?'checked':''}>
            <input type="radio" name="is_img_index" value="1" title="是" {:$info.is_img_index==1?'checked':''}>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">显示</label>
        <div class="layui-input-block">
            <input type="radio" name="is_display" value="0" title="否" {:$info.is_display==0?'checked':''}>
            <input type="radio" name="is_display" value="1" title="是" {:$info.is_display==1?'checked':''}>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="id" value="{$info.id}" />
            <button id="saveButton" type="submit" class="layui-btn"><i class="fa fa-check"></i> 提交</button>
            <button id="closeButton" type="button" class="layui-btn layui-btn-primary"><i
                class="fa fa-close"></i>
            关闭</button>
        </div>
    </div>
</form>
</div>
<script src="/static/admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/admin/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
      layui.use(['layer', 'form', 'laydate', 'element', 'upload'], function () {

        var $ = layui.$, layer = layui.layer, table = layui.table, laydate = layui.laydate, form = layui.form, upload = layui.upload;
        var indexFrame = parent.layer.getFrameIndex(window.name); //获取窗口索引

        $("#saveButton").on('click', function () {
            var loading = layer.open({ type: 3 });
            $.ajax({
                url: "{:url('edit')}",
                type: 'post',
                data: $("#DataForm").serialize(),
                success: function (data) {
                    console.log(data);
                    layer.close(loading);
                    if (data.code == 0) {
                        parent.tableReload();
                        parent.layer.close(indexFrame);
                        parent.layer.msg(data.msg);
                    } else {
                        layer.msg(data.msg);
                    }
                }
            })
            return false;
        })

        $("#closeButton").on('click', function () {
            parent.layer.close(indexFrame);
        })
        upload.render({
                elem: '#upload_img', url: "{:url('common/images')}", done: function (res) {
                    $("#img").val(res.data.name);
                    layer.msg(res.msg);
                }
            });
        });
</script>
</body>
</html>